package com.lap.mybatis.starter.autoconfigure;

import com.lap.mybatis.starter.processor.MybatisHelper;
import com.lap.mybatis.starter.processor.MybatisProcessor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;

/**
 * Mybatis 自动配置
 *
 * @author Shuisheng Lao(劳水生)
 * @version 1.0.0
 */
@Slf4j
@AutoConfiguration
public class MybatisAutoConfiguration {

  @Bean
  @ConditionalOnBean(SqlSessionFactory.class)
  MybatisHelper mybatisHolder(SqlSessionFactory sqlSessionFactory) {
    log.info("Initializer mybatis helper");
    return new MybatisHelper(sqlSessionFactory);
  }

  @Bean
  @ConditionalOnBean(MybatisHelper.class)
  MybatisProcessor mybatisProcessor(MybatisHelper mybatisHelper) {
    log.info("Initializer mybatis processor");
    return new MybatisProcessor(mybatisHelper);
  }
}
